<template>
	<view class="page">
		<view class="info_box">
			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">语音及其他检测</view>
				<view class="gcxt_b_wy_reason" style="margin: 20rpx 0;">
					<text sty>语音拨打测试</text>
				</view>

				<view class="gcxt_b_wy">
					<text>4G语音：</text>
					<u-checkbox-group  @change="groupChange4g" v-model="params.voice_4Gid" style="margin-top: 20rpx;width: 80%;justify-content: space-between;flex-wrap: wrap;">
						<u-checkbox v-for="(item,index) in yy4g" :key="index" :name="item.id" size="13" style="margin-bottom: 20rpx;" labelSize="13" :label="item.title"></u-checkbox>
				 

					</u-checkbox-group>
				</view>

				<view class="gcxt_b_wy">
					<text>5G语音：</text>
					<u-checkbox-group @change="groupChange5g" v-model="params.voice_5Gid" style="margin-top: 20rpx;width: 80%;justify-content: space-between;flex-wrap: wrap;">
						<u-checkbox size="13" style="margin-bottom: 20rpx;"  :name="item.id" labelSize="13" v-for="(item,index) in yy5g" :key="index"  :label="item.title"></u-checkbox>
		 

					</u-checkbox-group>
				</view>

				<view class="gcxt_b_wy">
					<text>监控：</text>
					<u-checkbox-group @change="groupChangejk"  v-model="params.monitor_id" style="margin-top: 20rpx;width: 80%;justify-content: space-between;flex-wrap: wrap;">
						<u-checkbox size="13" style="margin-bottom: 20rpx;"  :name="item.id" v-for="(item,index) in jkData" :key="index" labelSize="13" :label="item.title"></u-checkbox>
						 

					</u-checkbox-group>
				</view>
				
				<view class="gcxt_b_wy">
					<text>线缆/接头是否正常：</text>
					<u-radio-group  style="margin-top: 20rpx;" @change="chooseRR" v-model="params.is_cable_connectors">
						<u-radio shape="circle" name="2" size="14" style="margin-bottom: 20rpx;margin-right: 40rpx;" labelSize="14"  label="是"></u-radio>
						<u-radio shape="circle" name="1" size="14" style="margin-bottom: 20rpx;" labelSize="14"  label="否"></u-radio>
					</u-radio-group>
				 
				</view>
				
				<view class="gcxt_b_wy">
					<text>电源安全性检查：</text>
					<u-radio-group   @change="chooseRRR" v-model="params.is_power_supply" style="margin-top: 20rpx;">
						<u-radio shape="circle" size="14" name="1" style="margin-bottom: 20rpx;margin-right: 40rpx;" labelSize="14"  label="正常"></u-radio>
						<u-radio shape="circle" size="14" name="2" style="margin-bottom: 20rpx;" labelSize="14"  label="隐患"></u-radio>
					</u-radio-group>
				 
				</view> 

				<!-- <view class="gcxt_b_wy_reason">
					<text sty>故障说明：</text>
					<u--input placeholder="请输入具体说明" border="none"></u--input>
				</view> -->
			</view>
			
			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">维修结果</view> 
				 <view class="info_box_base_item" style="font-size: 25rpx;margin: 10rpx 0;">
				 	<text>维修内容描述：</text>
				 	<u--textarea  placeholder="请输入内容" v-model="params.repair_desc"></u--textarea>
				 </view> 
			</view>
			
			<view class="btn" @click="cofirmFun">提交</view>
		</view>
	</view>
</template>

<script>
	import {
		api,
		apiBaseUrl,
		http
	} from '@/config/common.js'
	export default {
		data() {
			return {
				id:'',
				fileList1: [],
				fileList2: [],
				yy4g:[],
				yy5g:[],
				jkData:[],
				params:{
					voice_4Gid:[],
					voice_5Gid:[],
					monitor_id:[],
					is_cable_connectors:'',
					is_power_supply:'',
					repair_desc:''
				}
			}
		},
		components: {},
		filters: {},
		mounted() {},
		onLoad(e) {
			this.id = e.id
			this.get4GYy()
			this.get5GYy()
			this.getJk()
			this.lookInfo()
		},
		onShow() {},
		onPageScroll(e) {},
		beforeDestroy() {},
		methods: {
			lookInfo() {
				uni.showLoading({})
				api.post('/api/shop/submit_maindetectionresult', {
					main_id: this.id,
					type: 2
				}).then(res => {  
					let rst = res.data  
					uni.hideLoading()
					if (rst.code == 1) {
						if (rst.data) { 
							this.params = rst.data 
							this.params.voice_4Gid = rst.data.voice_4Gid?rst.data.voice_4Gid.map(item => parseInt(item,10)):[]
							this.params.voice_5Gid = rst.data.voice_5Gid?rst.data.voice_5Gid.map(item => parseInt(item,10)):[]
							this.params.monitor_id = rst.data.monitor_id?rst.data.monitor_id.map(item => parseInt(item,10)):[]
								
							this.params.is_cable_connectors = rst.data.is_cable_connectors.toString()
							this.params.is_power_supply = rst.data.is_power_supply.toString()
						}
						
					}
			
				}).catch(err => {
					uni.hideLoading()
				})
			},
			chooseRR(e){
				this.params.is_cable_connectors = e
			},
			chooseRRR(e){
				this.params.is_power_supply = e
			},
			groupChangejk(e){
				this.params.monitor_id = e
			},
			groupChange5g(e){
				this.params.voice_5Gid = e
			},
			groupChange4g(e){
				this.params.voice_4Gid = e
			},
			//4G语音
			get4GYy() {
				uni.showLoading({})
				api.post('/api/shop/engin_voicecall_faultproblemdesc_faultfind', {type:0}).then(res => {
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.yy4g = rst.data
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			
			//5G语音
			get5GYy() {
				uni.showLoading({})
				api.post('/api/shop/engin_voicecall_faultproblemdesc_faultfind', {type:1}).then(res => {
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.yy5g = rst.data
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			
			//监控
			getJk() {
				uni.showLoading({})
				api.post('/api/shop/engin_voicecall_faultproblemdesc_faultfind', {type:2}).then(res => {
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.jkData = rst.data
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			cofirmFun(){
				let rst = this.params 
				rst.voice_4Gid = this.params.voice_4Gid.join(',')
				rst.voice_5Gid = this.params.voice_5Gid.join(',')
				rst.monitor_id = this.params.monitor_id.join(',') 
				uni.showLoading({})
				api.post('/api/shop/submit_maindetectionresult', {
					main_id: this.id,
					type: 1,
					...rst
				}).then(res => {
					let rst = res.data
					
					uni.hideLoading()
					if (rst.code == 1) {
						 uni.navigateTo({
						 	url:'/pages/gcwx/index'
						 })
					} else {
						uni.$u.toast(rst.msg)
					}
				
				}).catch(err => {
					uni.hideLoading()
				})
				
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			}
		}
	};
</script>

<style scoped>
	.info_box_base_item_img_title {
		font-size: 25rpx;
		margin: 20rpx 0;
	}
	.info_box_base_item_1_item_i {
		width: 30%;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 3%;
	}

	.down_link {
		color: rgb(11, 125, 218);
		font-size: 25rpx;
	}

	.btn {
		width: 500rpx;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		margin: 0 auto;
		margin-top: 40rpx;
		background-color: rgb(70, 179, 255);
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}

	::v-deep .uni-input-input {
		font-size: 26rpx;
	}

	::v-deep .uni-input-placeholder {
		font-size: 26rpx;
	}

	.gcxt_b_wy_reason {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.gcxt_b_wy {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 20rpx 0;
		flex-wrap: wrap;
	}

	.info_box_base {
		border: 1px solid rgb(235, 229, 229);
		padding: 20rpx;
		font-size: 26rpx;
		margin-top: 20rpx;
	}

	.info_box_base_item {
		line-height: 50rpx;
		word-wrap: break-word;
		/* 允许在单词内换行 */
		overflow-wrap: break-word;
		/* 同上，现代浏览器推荐使用这个属性别名 */
		white-space: normal;
		/* 允许自动换行 */
	}

	.info_box {
		width: 710rpx;
		margin: 0 auto;
		padding-bottom: 40rpx;
	}

	page {
		background-color: #fff;
	}
</style>